route.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { NextRequest, NextResponse } from 'next/server';
  2. import { ResultDto } from '@/dtos/response/common';
  3. import { fetchJson } from '@/lib/utils/server';
  4. export async function GET(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  5. const { path } = await params;
  6. const endpoint = `/api/mypage/${path.join('/')}`;
  7. const url = new URL(request.url);
  8. const res: ResultDto = await fetchJson(`${endpoint}${url.search}`, {
  9. method: 'GET'
  10. });
  11. return NextResponse.json(res);
  12. }
  13. export async function POST(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  14. const { path } = await params;
  15. const endpoint = `/api/mypage/${path.join('/')}`;
  16. const contentType = request.headers.get('content-type') || '';
  17. let body: string | FormData | undefined;
  18. if (contentType.includes('multipart/form-data')) {
  19. body = await request.formData();
  20. } else {
  21. body = JSON.stringify(await request.json());
  22. }
  23. const res: ResultDto = await fetchJson(endpoint, {
  24. method: 'POST',
  25. body
  26. });
  27. return NextResponse.json(res);
  28. }
  29. export async function DELETE(_: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  30. const { path } = await params;
  31. const endpoint = `/api/mypage/${path.join('/')}`;
  32. const res: ResultDto = await fetchJson(endpoint, {
  33. method: 'DELETE'
  34. });
  35. return NextResponse.json(res);
  36. }